package org.activision.content.combat;

import org.activision.model.Entity;
import org.activision.model.Item;
import org.activision.model.npc.Npc;
import org.activision.model.player.Player;
import org.activision.model.player.Skills;
import org.activision.util.CombatManager;
import org.activision.util.Misc;
import org.activision.util.ProjectileManager;

public class Combat {

	private Entity entity;
	private Entity target;
	public byte delay;
	private byte prayerBeforeHitDelay;
	private byte hitDelay;
	private byte prayerAfterHitDelay;
	private CombatHitDefinitions combatHitDefinitions;
	private long lastAttackedTime;
	public Combat(Entity entity) {
		this.entity = entity;
		prayerBeforeHitDelay = -1;
		hitDelay = -1;
		prayerAfterHitDelay = -1;
	}
	
	public void processDelays() {
		if(delay > 0)
			delay--;
		if(hitDelay > 0)
			hitDelay--;
		if(prayerBeforeHitDelay > 0)
			prayerBeforeHitDelay--;
		if(prayerAfterHitDelay > 0)
			prayerAfterHitDelay--;
	}
	
	public void removeTarget() {
		target = null;
		entity.resetTurnTo();
	}
	
	public void clear() {
		prayerBeforeHitDelay = -1;
		hitDelay = -1;
		prayerAfterHitDelay = -1;
		combatHitDefinitions = null;
	}
	
	private boolean removedTarget() {
		if(target == null)
			return true;
		if (!((Player) target).isOnline() || target.isDead()) {
			removeTarget();
			return true;
		}
		if (!entity.getLocation().withinDistance(target.getLocation(), 25)) {
			removeTarget();
			return true;
		}
		return false;
	}
	
	public boolean hasTarget() {
		return target != null;
	}
	public void attack(Entity target) {
		if(entity.isDead())
			return;
		this.target = target;
		this.entity.turnTo(this.target);
	}
	public boolean processAttack() {
		if(removedTarget())
			return false;
		
		int distance = (int) Math.round(entity.getLocation().getDistance(target.getLocation()));
		int entityDistance  = target instanceof Npc ? (byte) ((Npc) target).getNpcdefinition().size : 1;
		if (entity instanceof Player) {
			final Player p = (Player) entity;
			
			if (p.isDead() || System.currentTimeMillis() < (p.getCombatDefinitions().getLastEmote() - 600)) {
				removeTarget();
				return false;
			}
			
			int weaponId = p.getEquipment().get(3) == null ? -1 : p.getEquipment().get(3).getId();
			if(weaponId > -1)
				entityDistance += CombatManager.distForWeap(weaponId);
			if(weaponId == 4153 && p.getCombatDefinitions().isSpecialOn() && p.getCombatDefinitions().getSpecpercentage() >= CombatManager.getSpecAmt(weaponId))
				delay = 0;
		}
		if (distance == 0 || distance > entityDistance) {
			entity.getWalk().reset();
			entity.getWalk().addToWalkingQueueFollow(
					target.getLocation().getX() - (entity.getLocation().getRegionX() - 6) * 8
					, target.getLocation().getY() - (entity.getLocation().getRegionY() - 6) * 8);
			//removeTarget();
			if((entity.getWalk().getRunDir() == -1 || distance > 2) &&  (entity.getWalk().getWalkDir() == -1 || distance > 1))
			return false;
		}
		if(delay > 0)
			return true;
		
		this.entity.turnTo(this.target);
		if (entity instanceof Player)
			 processPlayer();
		return true;
	}
	
	public void processPlayer() {
		final Player p = (Player) entity;
		final Entity target = this.target;
		
		final byte attackStyle = p.getCombatDefinitions().getAttackStyle();
		
		final int weaponId = p.getEquipment().get(3) == null ? -1 : p.getEquipment().get(3).getId();
		final int ammoId = p.getEquipment().get(13) == null ? -1 : p.getEquipment().get(13).getId();
		
		int specAmt = CombatManager.getSpecAmt(weaponId);
		
		final boolean specialOn = p.getCombatDefinitions().isSpecialOn() && p.getCombatDefinitions().getSpecpercentage() >= specAmt;
		if (specAmt == -1 && p.getCombatDefinitions().isSpecialOn()) {
			//set special off
			p.getCombatDefinitions().setSpecialOff();
			return;
		}
		if (!specialOn && p.getCombatDefinitions().isSpecialOn()) {
			p.getFrames().sendChatMessage(0, "You don't have enough power left.");
			p.getCombatDefinitions().setSpecialOff();
			return;
		}
		if(specialOn) {
			p.getCombatDefinitions().drainSpec(specAmt);
			p.getCombatDefinitions().setSpecialOff();
		}
		
		int maxHit = getPlayerMaxHit(attackStyle, weaponId, CombatManager.isRangingWeapon(weaponId), specialOn);
		int speed = CombatManager.getSpeedForWeapon(weaponId);
		
		int distance = Math.round(entity.getLocation().getDistance(target.getLocation())) > 3  ? 2 : 1;
		
		sendPlayerAttackEmote(specialOn, weaponId);
		sendAttackGraphic(specialOn, weaponId, ammoId, target);
		sendHit(specialOn, weaponId, maxHit, distance, target);
		this.delay += (byte) speed;
	}
	
	public void processPrayerBeforeHit() {
		if(combatHitDefinitions == null)
			return;
		if(prayerBeforeHitDelay != 0)
			return;
		Entity target = combatHitDefinitions.getTarget();
		if (target instanceof Player)
			if (!((Player) target).isOnline() || target.isDead())
				return;
		
		if(combatHitDefinitions.isSapWarrior())
			ProjectileManager.sendGlobalProjectile(entity, target,	2215, 35, 35, 30, 0, 140);
		if(combatHitDefinitions.isSapRanger())
			ProjectileManager.sendGlobalProjectile(entity, target,2218, 35, 35, 30, 0, 140);
		if(combatHitDefinitions.isSapSpirit())
			ProjectileManager.sendGlobalProjectile(entity, target,2224, 35, 35, 30, 0, 140);
		prayerBeforeHitDelay = -1;
	}
	
	public void processPrayerAfterHit() {
		if(combatHitDefinitions == null)
			return;
		if(prayerAfterHitDelay != 0)
			return;
		Entity target = combatHitDefinitions.getTarget();
		if (target instanceof Player) {
			if (!((Player) target).isOnline() || target.isDead()) {
				combatHitDefinitions = null;
				return;
			}
		}
		
		if(combatHitDefinitions.isSoulSplitPray()) {
			int gain = combatHitDefinitions.getMaxDamage()/50;
			((Player) entity).getSkills().heal(gain * 10);
			if (target instanceof Player)
				((Player) target).getSkills().drainPray(gain);
			target.graphics(2264);
			ProjectileManager.sendGlobalProjectile(target, entity,2263, 11, 11, 30, 0, 0);
		}
		if (combatHitDefinitions.isSapWarrior()) {
			boolean bost = ((Player) entity).getPrayer().usingBoost(0);
			((Player) target).getSkills().set(0,((Player) target).getSkills().getLevelForXp(0) * (bost ? 80 : 90) / 100);
			((Player) target).getSkills().set(2,((Player) target).getSkills().getLevelForXp(2) * (bost ? 80 : 90) / 100);
			((Player) target).getSkills().set(1,((Player) target).getSkills().getLevelForXp(1) * (bost ? 80 : 90) / 100);
			target.graphics(2216);
			((Player) entity).getPrayer().setBoost(0, true);
		}
		if (combatHitDefinitions.isSapRanger()) {
			boolean bost = ((Player) entity).getPrayer().usingBoost(1);
			((Player) target).getSkills().set(4,((Player) target).getSkills().getLevelForXp(4) * (bost ? 80 : 90) / 100);
			((Player) target).getSkills().set(1,((Player) target).getSkills().getLevelForXp(1) * (bost ? 80 : 90) / 100);
			target.graphics(2219);
			((Player) entity).getPrayer().setBoost(1, true);
		}
		if (combatHitDefinitions.isSapSpirit()) {
			target.graphics(2225);
		}
		if (combatHitDefinitions.isLeechAttack()) {
			boolean bost = ((Player) entity).getPrayer().usingBoost(3);
			((Player) target).getSkills().set(0,((Player) target).getSkills().getLevelForXp(0) * (bost ? 75 : 90) / 100);
			target.graphics(2232);
			((Player) entity).getPrayer().setBoost(3, true);
		}
		if (combatHitDefinitions.isLeechRanged()) {
			boolean bost = ((Player) entity).getPrayer().usingBoost(5);
			((Player) target).getSkills().set(4,((Player) target).getSkills().getLevelForXp(4) * (bost ? 75 : 90) / 100);
			target.graphics(2238);
			((Player) entity).getPrayer().setBoost(5, true);
		}
		if (combatHitDefinitions.isLeechDefence()) {
			boolean bost = ((Player) entity).getPrayer().usingBoost(6);
			((Player) target).getSkills().set(1,((Player) target).getSkills().getLevelForXp(1) * (bost ? 75 : 90) / 100);
			target.graphics(2246);
			((Player) entity).getPrayer().setBoost(6, true);
		}
		if (combatHitDefinitions.isLeechStrength()) {
			boolean bost = ((Player) entity).getPrayer().usingBoost(7);
			((Player) target).getSkills().set(2,((Player) target).getSkills().getLevelForXp(2) * (bost ? 75 : 90) / 100);
			target.graphics(2250);
			((Player) entity).getPrayer().setBoost(7, true);
		}
		
		prayerAfterHitDelay = -1;
		combatHitDefinitions = null;
	}
	
	public void processHit() {
		if(combatHitDefinitions == null)
			return;
		if(hitDelay != 0)
			return;
		Entity target = combatHitDefinitions.getTarget();
		if (target instanceof Player) {
			if (!((Player) target).isOnline() || target.isDead()) {
				if(prayerAfterHitDelay == -1)
					combatHitDefinitions = null;
				return;
			}
			((Player) target).getCombat().setLastAttackedTime(System.currentTimeMillis());
		}
		/*
		 * Prayer while hitting
		 */
		int hit1 = PlayerProbOfHiting(target, combatHitDefinitions.getMaxDamage(), combatHitDefinitions.getBonuses(), combatHitDefinitions.getWeaponId(), combatHitDefinitions.isSpecialOn()) ? combatHitDefinitions.getMaxDamage() : 0;
		if (combatHitDefinitions.isMeleeDeflectPray() || combatHitDefinitions.isRangeDeflectPray()) {
			if (hit1 * 10 / 100 > 0)
				entity.hit(hit1 * 10 / 100);
			target.animate(12573);
			target.graphics(combatHitDefinitions.isMeleeDeflectPray() ? 2230 : 2229);
		}	else if (combatHitDefinitions.isSoulSplitPray())
			ProjectileManager.sendGlobalProjectile(entity, target, 2263, 11, 11, 30, 20, 0);
		if (combatHitDefinitions.isLeechAttack() || combatHitDefinitions.isLeechRanged() || combatHitDefinitions.isLeechDefence() || combatHitDefinitions.isLeechStrength())
			ProjectileManager.sendGlobalProjectile(target, entity, combatHitDefinitions.isLeechAttack() ? 2231 : (combatHitDefinitions.isLeechRanged() ? 2236 : (combatHitDefinitions.isLeechDefence() ? 2244 : 2248)), 30,30, 30, 0, 0);
		else if (combatHitDefinitions.isTurmoilPray())
			((Player) target).getPrayer().setBoost(8, true);
		
		/*
		 * Defence Animation
		 */
		if (!combatHitDefinitions.isMeleeDeflectPray() && !combatHitDefinitions.isRangeDeflectPray())
			target.animate(CombatManager.getDefenceEmote(target));
		
		/*
		 * Hit
		 */
		if (combatHitDefinitions.isSpecialOn() && combatHitDefinitions.getWeaponId() == 14484) {
			int totalDamage = 0;
			int hit2 = hit1 == 0 ? (PlayerProbOfHiting(target, combatHitDefinitions.getMaxDamage(), combatHitDefinitions.getBonuses(), combatHitDefinitions.getWeaponId(), combatHitDefinitions.isSpecialOn()) ? combatHitDefinitions.getMaxDamage() : 0) : hit1;
			if(hit1 == 0 && hit2 == 0) {
				int hit3 = PlayerProbOfHiting(target, combatHitDefinitions.getMaxDamage(), combatHitDefinitions.getBonuses(), combatHitDefinitions.getWeaponId(), combatHitDefinitions.isSpecialOn()) ? combatHitDefinitions.getMaxDamage() : 0;
				if(hit3 == 0) {
					int hit4 = PlayerProbOfHiting(target, combatHitDefinitions.getMaxDamage(), combatHitDefinitions.getBonuses(), combatHitDefinitions.getWeaponId(), combatHitDefinitions.isSpecialOn()) ? combatHitDefinitions.getMaxDamage() : 0;
					if(hit4 == 0) {
						target.hit(hit2);
						target.hit(hit1);
						target.hit(1);
						target.hit(hit3);
						totalDamage = 1;
					}else{
						target.hit(hit2);
						target.hit(hit1);
						target.hit((int) (hit4*1.5));
						target.hit(hit3);
						totalDamage = (int) (hit4*1.5);
					}
				}else{
					target.hit(hit2);
					target.hit(hit1);
					target.hit(hit3);
					target.hit(hit3);
					totalDamage = hit3*2;
				}
			} else {
				target.hit(hit1 == 0 ? hit2 : hit2/2);
				target.hit(hit1);
				target.hit(hit2/4);
				target.hit(hit1 == 0 ? hit2/2 : hit2/4);
				totalDamage = (hit1 == 0 ? hit2 : hit2/2)+hit1+(hit1 == 0 ? hit2/2 : hit2/4)+(hit2/4);
			}
			combatHitDefinitions.setMaxDamage(totalDamage);
		}else{
			target.hit(hit1);
			combatHitDefinitions.setMaxDamage(hit1);
		}
		hitDelay = -1;
		if(prayerAfterHitDelay == -1)
		combatHitDefinitions = null;
	}
	
	public void sendHit(boolean specialon, final int weaponId, final int maxHit, final int distance, final Entity target) {
		int randomDamage = Misc.random(maxHit);
		
		
		if(specialon) {
			int p1 = maxHit*5/10;
			double m1 = 1.25+CombatManager.getSpecDamageDoublePercentage(weaponId);
			if(p1 > randomDamage && m1 > Math.random()) {
				int d1 = maxHit-p1;
				randomDamage = p1 + Misc.random(d1);
			}
		}
		
		final boolean protectPray = randomDamage > 0 && (target instanceof Player && (CombatManager.isRangingWeapon(weaponId) && (((Player) target).getPrayer().usingPrayer(0, 18)) || ((Player) target).getPrayer().usingPrayer(0, 19)));
		final boolean sapWarrior = randomDamage > 0 && !CombatManager.isRangingWeapon(weaponId) && (target instanceof Player && entity instanceof Player && ((Player) entity).getPrayer().usingPrayer(1, 1)) && Misc.random(14) == 1;
		if (protectPray)
			randomDamage = target instanceof Player ? randomDamage * 60 / 100 : 0;
		final boolean sapRanger = randomDamage > 0 && CombatManager.isRangingWeapon(weaponId) && (target instanceof Player && entity instanceof Player && ((Player) entity).getPrayer().usingPrayer(1, 2)) && Misc.random(14) == 1;
		final boolean sapSpirit = !sapRanger && !sapWarrior && randomDamage > 0 && (target instanceof Player && entity instanceof Player && ((Player) entity).getPrayer().usingPrayer(1, 4)) && Misc.random(14) == 1;
		final boolean leechAttack = randomDamage > 0 && !CombatManager.isRangingWeapon(weaponId) && (target instanceof Player && entity instanceof Player && ((Player) entity).getPrayer().usingPrayer(1, 10)) && Misc.random(14) == 1;
		final boolean leechRanged = randomDamage > 0 && CombatManager.isRangingWeapon(weaponId)	&& (target instanceof Player && entity instanceof Player && ((Player) entity).getPrayer().usingPrayer(1, 11)) && Misc.random(14) == 1;
		final boolean leechDefence = !leechAttack && !leechRanged && randomDamage > 0 && (target instanceof Player && entity instanceof Player && ((Player) entity).getPrayer().usingPrayer(1, 13)) && Misc.random(14) == 1;
		final boolean leechStrength = !leechAttack&& !leechDefence && randomDamage > 0 && !CombatManager.isRangingWeapon(weaponId) && (target instanceof Player && entity instanceof Player && ((Player) entity).getPrayer().usingPrayer(1, 14)) && Misc.random(14) == 1;
		final boolean rangeDeflectPray = randomDamage > 0 && (target instanceof Player && CombatManager.isRangingWeapon(weaponId) && ((Player) target).getPrayer().usingPrayer(1, 8));
		final boolean meleeDeflectPray = randomDamage > 0 && (target instanceof Player && !CombatManager.isRangingWeapon(weaponId) && ((Player) target).getPrayer().usingPrayer(1, 9));
		if (rangeDeflectPray || meleeDeflectPray)
			randomDamage = target instanceof Player ? randomDamage * 60 / 100 : 0;
		final boolean soulSplitPray = (entity instanceof Player && ((Player) entity).getPrayer().usingPrayer(1, 18));
		final boolean turmoilPray = (target instanceof Player && ((Player) target).getPrayer().usingPrayer(1, 19) && !((Player) target).getPrayer().usingBoost(8));
		
		if(sapWarrior || sapRanger || sapSpirit) {
		if (sapWarrior) {
			entity.animate(12569);
			target.graphics(2214);
		}
		if (sapRanger) {
			entity.animate(12569);
			target.graphics(2217);
		}
		if (sapSpirit) {
			entity.animate(12569);
			target.graphics(2223);
		}
		prayerBeforeHitDelay = 1;
		}
		short[] bonuses =  entity instanceof Player ? ((Player) entity).getCombatDefinitions().getBonus() : new short[15];
		combatHitDefinitions = new CombatHitDefinitions(target, weaponId, randomDamage, specialon, bonuses ,
				meleeDeflectPray, rangeDeflectPray,
				protectPray,
				soulSplitPray,
				sapWarrior, sapRanger, sapSpirit,
				leechAttack, leechRanged, leechDefence,leechStrength,
				turmoilPray);
		hitDelay = (weaponId == 4153 && specialon) ? 0 : (byte) distance;
		
		if(soulSplitPray ||  sapWarrior || sapRanger || sapSpirit || leechAttack || leechRanged || leechDefence || leechStrength)
			prayerAfterHitDelay = (byte) (distance+1);
	}
	
	private boolean PlayerProbOfHiting(Entity target, int attackStyle, short[] bonus, int weaponId, boolean specialOn) {
		Player p = (Player) entity;
		if (target instanceof Player) { // TODO
			Player enemy = (Player) target;
			double att = bonus[1] + p.getSkills().getLevel(Skills.ATTACK);
			if(specialOn) {
				double multiplier = 0.25;
				multiplier += CombatManager.getSpecDamageDoublePercentage(weaponId)/2;
				att = att* multiplier;
			}	
			double def = enemy.getCombatDefinitions().getBonus()[6] + enemy.getSkills().getLevel(Skills.DEFENCE);
			double prob = att / def;
			if (prob > 0.80)
				prob = 0.80;
			return prob >= Math.random();
		}
		return true;
	}
	
	private int getPlayerMaxHit(int attackStyle, int weaponId, boolean isRanging, boolean specialOn) {
		Player p = (Player) entity;
		if (!isRanging) {
			int StrengthLvl = p.getSkills().getLevel(Skills.STRENGTH);
			double PrayerBonus = 1;
			if (p.getPrayer().usingPrayer(0, 1))
				PrayerBonus = 1.05;
			else if (p.getPrayer().usingPrayer(0, 6))
				PrayerBonus = 1.1;
			else if (p.getPrayer().usingPrayer(0, 14))
				PrayerBonus = 1.15;
			else if (p.getPrayer().usingPrayer(0, 25))
				PrayerBonus = 1.18;
			else if (p.getPrayer().usingPrayer(0, 26))
				PrayerBonus = 1.23;
			else if (p.getPrayer().usingPrayer(1, 14))
				PrayerBonus = p.getPrayer().usingBoost(7) ? 1.1 : 1.5;
			else if (p.getPrayer().usingPrayer(1, 19))
				PrayerBonus = (p.getPrayer().usingBoost(8) && target instanceof Player) ? 1.23 + (((Player)target).getSkills().getLevelForXp(Skills.STRENGTH)/1000) :  1.23;
			double OtherBonus = 1;
			int StyleBonus = 0;
			if (attackStyle == 0)
				StyleBonus = 0;
			else if (attackStyle == 2)
				StyleBonus = 1;
			else if (attackStyle == 3)
				StyleBonus = 3;
			double EffectiveStrenght = Math.round(StrengthLvl * PrayerBonus
					* OtherBonus)
					+ StyleBonus;
			int StrengthBonus = p.getCombatDefinitions().getBonus()[11];
			double BaseDamage = 13 + EffectiveStrenght + (StrengthBonus / 8)
					+ (EffectiveStrenght * StrengthBonus / 64);
			double finaldamage;
			if (specialOn)
				finaldamage = Math.floor(BaseDamage * CombatManager.getSpecDamageDoublePercentage(weaponId));
			 else
				finaldamage = Math.round(BaseDamage);
			if(CombatManager.wearingDharok(p))
				finaldamage += ((p.getSkills().getLevelForXp(3)*10) - p.getSkills().getHitPoints())/2;
			return (int) finaldamage;
		}
		return 0;
	}
	
	private void sendPlayerAttackEmote(boolean specialon, int weaponId) {
		Player p = (Player) entity;
		byte attackStyle = p.getCombatDefinitions().getAttackStyle();
		if(weaponId == -1) {
			this.entity.animate(attackStyle == 2 ? 422 : 423);
			return;
		}
		String itemName = new Item(weaponId).getDefinition().name;
		if (!specialon) {
			if (itemName.contains("whip"))
				this.entity.animate(1658);
			else if (itemName.contains("claws"))
				this.entity.animate(393);
			else if (weaponId == 6528)
				this.entity.animate(2661);
			else if (itemName.contains("pickaxe"))
				this.entity.animate(attackStyle == 2 ? 402 : 401);
			else if (itemName.contains("Dharok"))
				this.entity.animate(attackStyle == 2 ? 2067 : 2066);
			else if (itemName.contains("Verac"))
				this.entity.animate(2062);
			else if (itemName.contains("Granite maul"))
				this.entity.animate(1665);
			else if (itemName.contains("Guthan"))
				this.entity.animate(attackStyle == 2 ? 2081 : 2080);
			else if (itemName.contains("godsword") || itemName.contains("2h sword"))
				this.entity.animate(attackStyle == 2 ? 7048 : 7041);
			else if (itemName.contains("Saradomin sword"))
				this.entity.animate(attackStyle == 2 ? 7048 : 7041);
			else if (itemName.contains("Keris") || itemName.contains("dagger"))
				this.entity.animate(attackStyle == 2 ? 401 : 402);
			else if (itemName.contains("Karil"))
				this.entity.animate(2075);
			else if (!itemName.contains("Karil") && itemName.contains("crossbow"))
				this.entity.animate(4230);
			else if (itemName.contains("dart"))
				this.entity.animate(582);
			else if (itemName.contains("knife"))
				this.entity.animate(806);
			else if (itemName.contains("bow"))
				this.entity.animate(426);
			else
				this.entity.animate(451);
		}else {
			if(weaponId == 14484) {
				this.entity.animate(10961);
			}else if(weaponId == 1215) {
				this.entity.animate(1062);
			}else if(weaponId == 1305) {
				this.entity.animate(12031);
			}else if(weaponId == 1434) {
				this.entity.animate(1060);
			}else if(weaponId == 3204) {
				this.entity.animate(1665);
			}else if(weaponId == 4587) {
				this.entity.animate(12005);
			}else if(weaponId == 5698) {
				this.entity.animate(1062);
			}else if(weaponId == 4153) {
				this.entity.animate(1667);
			}else if(weaponId == 7158) {
				this.entity.animate(3157);
			}else if(weaponId == 10887) {
				this.entity.animate(5870);
			}else if(weaponId == 11694) {
				this.entity.animate(7074);
			}else if(weaponId == 11696) {
				this.entity.animate(7073);
			}else if(weaponId == 11698) {
				this.entity.animate(7071);
			}else if(weaponId == 11700) {
				this.entity.animate(7070);
			}else if(weaponId == 11730) {
				this.entity.animate(7072);
			}
		}
	}
	
	private void sendAttackGraphic(boolean specialon, int weaponId, int ammoId, Entity target) {
		if(weaponId == -1)
			return;
		String itemName = new Item(weaponId).getDefinition().name;
		if(!specialon) {
			if(weaponId == 868) {
				entity.graphics(225, 100 << 16);
			} else if(weaponId == 867) {
				entity.graphics(224, 100 << 16);
			} else if(weaponId == 866) {
				entity.graphics(223, 100 << 16);
			} else if(weaponId == 865) {
				entity.graphics(222, 100 << 16);
			} else if(weaponId == 864) {
				entity.graphics(221, 100 << 16);
			} else if(weaponId == 863) {
				entity.graphics(220, 100 << 16);
			} else if(weaponId == 4214) {
				entity.graphics(250, 100 << 16);
				ProjectileManager.sendGlobalProjectile(entity, target, 249, 34, 36, 41, 15, 0);
			} else if (itemName.contains("bow")) {
				if(ammoId == 882) {
					entity.graphics(19, 100 << 16);
					ProjectileManager.sendGlobalProjectile(entity, target, 10, 36, 40, 41, 15, 0);
				} else if(ammoId == 884) {
					entity.graphics(18, 100 << 16);
					ProjectileManager.sendGlobalProjectile(entity, target, 11, 36, 40, 41, 15, 0);
				} else if(ammoId == 886) {
					entity.graphics(20, 100 << 16);
					ProjectileManager.sendGlobalProjectile(entity, target, 12, 36, 40, 41, 15, 0);
				} else if(ammoId == 9706) {
					entity.graphics(25, 100 << 16);
					ProjectileManager.sendGlobalProjectile(entity, target, 25, 36, 40, 41, 15, 0);
				} else if(ammoId == 888) {
					entity.graphics(21, 100 << 16);
					ProjectileManager.sendGlobalProjectile(entity, target, 13, 36, 40, 41, 15, 0);
				} else if(ammoId== 890) {
					entity.graphics(22, 100 << 16);
					ProjectileManager.sendGlobalProjectile(entity, target, 14, 36, 40, 41, 15, 0);
				} else if(ammoId == 892) {
					entity.graphics(24, 100 << 16);
					ProjectileManager.sendGlobalProjectile(entity, target, 15, 36, 40, 41, 15, 0);
				}
			}
		}else{
			if(weaponId == 14484) {
				this.entity.graphics(1950);
				
			}else if(weaponId == 1215) {
				this.entity.graphics(252);
			}else if(weaponId == 1305) {
				this.entity.graphics(2117);
			}else if(weaponId == 1434) {
				this.entity.graphics(251);
			}else if(weaponId == 3204) {
				this.entity.graphics(282);
			}else if(weaponId == 4587) {
				this.entity.graphics(2118);
			}else if(weaponId == 5698) {
				this.entity.graphics(252);
			}else if(weaponId == 4153) {
				this.entity.graphics(1);
			}else if(weaponId == 7158) {
				this.entity.graphics(559);
			}else if(weaponId == 10887) {
				this.entity.graphics(1027);
			}else if(weaponId == 11694) {
				this.entity.graphics(1222);
			}else if(weaponId == 11696) {
				this.entity.graphics(1223);
			}else if(weaponId == 11698) {
				this.entity.graphics(1220);
			}else if(weaponId == 11700) {
				this.entity.graphics(2110);
			}else if(weaponId == 11730) {
				this.entity.graphics(1224);
			}
		}
	}

	public void setLastAttackedTime(long lastAttackedTime) {
		this.lastAttackedTime = lastAttackedTime;
	}

	public long getLastAttackedTime() {
		return lastAttackedTime;
	}
	
}

